package org.ciallo.easytokencore.annotation.handler;

import org.ciallo.easytokencore.annotation.EasyCheckLogin;
import org.ciallo.easytokencore.context.EasyContextHolder;
import org.ciallo.easytokencore.exception.EasyTokenInvalidException;

import java.lang.reflect.Method;

/**
 * Easy-Token 登录校验注解处理器实现类
 *
 * <p>核心功能：</p>
 * <ul>
 *   <li>处理@EasyCheckLogin注解标记的方法</li>
 *   <li>校验请求中的Token有效性</li>
 *   <li>抛出Token相关异常</li>
 * </ul>
 *
 * <p>实现说明：</p>
 * <ol>
 *   <li>通过getHandlerAnnotationClass()声明处理的注解类型</li>
 *   <li>checkMethod()实现具体的Token校验逻辑</li>
 *   <li>依赖EasyContextHolder获取请求上下文</li>
 * </ol>
 *
 * @Description: Easy-Token 登录校验注解处理器
 * @Author: Jukomu
 * @Package: org.ciallo.easytokencore.annotation.handler
 * @Project: easy-token-demo
 * @Version: 1.0.0
 * @name: EasyCheckLoginHandler
 * @Date: 2025/5/6-15:50
 * @Filename: EasyCheckLoginHandler
 * @see EasyCheckLogin
 * @see EasyAnnotationHandlerInterface
 * @see EasyTokenInvalidException
 */
public class EasyCheckLoginHandler implements EasyAnnotationHandlerInterface<EasyCheckLogin> {
    @Override
    public Class<EasyCheckLogin> getHandlerAnnotationClass() {
        return EasyCheckLogin.class;
    }

    @Override
    public void checkMethodPreHandle(EasyCheckLogin at, Method method) {
        EasyContextHolder.getToken().isVerified();
    }

    @Override
    public void checkMethodPostHandle(EasyCheckLogin at, Method method) {
    }

    @Override
    public void checkMethodAfterCompletion(EasyCheckLogin at, Method method) {
    }
}
